package top.lucky.kafka.producer;

import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;

import java.util.Map;

/**
 * @author Jane
 * @date 2022/12/25, 15:55
 */
public class MyPartitioner implements Partitioner {
	@Override
	public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {
		//获取数据
		String msg = value.toString();
		int partition ;
		if (msg.contains("miaojingyun")) {
			partition = 0;
		}else
			partition = 1;
		return partition;
	}
	
	@Override
	public void close() {
	
	}
	
	@Override
	public void configure(Map<String, ?> configs) {
	
	}
}
